package com.poorstu.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;

import com.common.base.web.BaseAction;
import com.poorstu.manager.ClassAndCollegeManager;
import com.poorstu.manager.LoginMeg;
import com.poorstu.manager.RoleManager;
import com.poorstu.model.ClassMod;
import com.poorstu.model.LoginMod;
import com.poorstu.model.RoleMod;

public class MenberChangeAction extends BaseAction {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		
		try{
		DynaActionForm dyna=(DynaActionForm)form;
		LoginMod  loginMod=new LoginMod();
		int allUserId=(Integer)dyna.get("userId");
		String userName=(String)dyna.get("userName");
		String userAccount=(String)dyna.get("userAccount");
		String userpwd=(String)dyna.get("userpwd");
	
		int role=(Integer)dyna.get("role");
	//	int college=(Integer)dyna.get("college");
		int classes=(Integer)dyna.get("classes");
		
		RoleManager roleManager=(RoleManager)getBean("roleMeg");
		RoleMod roleMod= roleManager.selectRoleById(role);
		ClassAndCollegeManager classAndCollege=(ClassAndCollegeManager)getBean("classAndCollegeManager");
		ClassMod classMod=classAndCollege.selectClassById(classes);
		
		
		loginMod.setId(allUserId);
		loginMod.setName(userName);
		loginMod.setPassword(userpwd);
		loginMod.setUserAccount(userAccount);
		
		loginMod.setClassId(classMod);
		loginMod.setRoleId(roleMod);
		
		LoginMeg loginMeg=(LoginMeg)getBean("loginMeg");
		loginMeg.menberUpdate(loginMod);
		
		return mapping.findForward("succ");
		}catch(Exception e){
			e.printStackTrace();
		return mapping.findForward("failure"); 
		}
		

		  
	}
	

}
